import Vue from 'vue'
import Vuex from 'vuex'
import routes from '../../../bk-web-foundation/src/store/routes'
import settings from '../../../bk-web-foundation/src/store/settings'
import user from '../../../bk-web-foundation/src/store/user'
import utils from '../../../bk-web-foundation/src/store/utils'

Vue.use(Vuex)

const files = require.context('./modules', false, /\.js$/)
const modules = {}
files.keys().forEach((key) => {
  const moduleName = key.replace(/(\.\/|\.js)/g, '')
  modules[moduleName] = files(key).default
  modules[moduleName].namespaced = true
})

modules.routes = routes
modules.settings = settings
modules.user = user
modules.utils = utils

const store = new Vuex.Store({
  modules
})

export default store
